package com.android.pagemarket.ui.widget;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout.LayoutParams;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.android.pagemarket.R;
import com.android.pagemarket.business.logic.InitManager;

/*********************************************************
 * @author : zhaohua
 * @version : 2012-11-1
 * @see : 拨打电话的弹出框
 * @Copyright : copyrights reserved by personal 2007-2011
 **********************************************************/
public class CallPopWindow extends PopupWindow implements OnClickListener
{
    private Context mContext;
    private TextView tx_tip;
    private TextView tx_phone;
    private String  callPhone;
    
    public CallPopWindow(Context context)
    {
        super(LayoutInflater.from(context).inflate(R.layout.popview_call,null), 
              LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
        mContext = context;
        setBackgroundDrawable(new ColorDrawable(0x99000000));
        setTouchable(true);
        setFocusable(true);                          
        initViews();
    }
    
    private void initViews()
    {
        View v = getContentView();
        v.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                dismiss();
            }
        });
        tx_tip = (TextView)v.findViewById(R.id.tx_tip);
        tx_phone = (TextView)v.findViewById(R.id.tx_phone);
        
        v.findViewById(R.id.btn_call).setOnClickListener(this);
        v.findViewById(R.id.btn_see_later).setOnClickListener(this);
    }
    
    public void setTipText(String text)
    {
        tx_tip.setText(text);
    }
    
    public void setPhoneText(String text)
    {
        tx_phone.setText(text);
        if(TextUtils.isEmpty(text))
        {
            tx_phone.setVisibility(View.GONE);
        }
    }
    
    public void setCallPhone(String phone)
    {
        callPhone = phone;
    }

    @Override
    public void onClick(View v)
    {
        switch(v.getId())
        {
            case R.id.btn_call:
            {
                if(TextUtils.isEmpty(callPhone)) return;
                dismiss();
                Intent it = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + callPhone));
                mContext.startActivity(it);                
                break;
            }
            case R.id.btn_see_later:
            {
                dismiss();
                break;
            }
        }
    }
    
    
}
